var t = require;
var e = module;
var o = exports;
var a,
    i =
        (this && this.__extends) ||
        ((a = function (t, e) {
            return (a =
                Object.setPrototypeOf ||
                ({__proto__: []} instanceof Array &&
                    function (t, e) {
                        t.__proto__ = e;
                    }) ||
                function (t, e) {
                    for (var o in e) Object.prototype.hasOwnProperty.call(e, o) && (t[o] = e[o]);
                })(t, e);
        }),
        function (t, e) {
            a(t, e);
            function o() {
                this.constructor = t;
            }
            t.prototype = null === e ? Object.create(e) : ((o.prototype = e.prototype), new o());
        }),
    n =
        (this && this.__decorate) ||
        function (t, e, o, a) {
            var i,
                n = arguments.length,
                r = n < 3 ? e : null === a ? (a = Object.getOwnPropertyDescriptor(e, o)) : a;
            if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(t, e, o, a);
            else
                for (var s = t.length - 1; s >= 0; s--)
                    (i = t[s]) && (r = (n < 3 ? i(r) : n > 3 ? i(e, o, r) : i(e, o)) || r);
            return n > 3 && r && Object.defineProperty(e, o, r), r;
        };
Object.defineProperty(o, "__esModule", {value: !0});
var r = t("ShopGroupItemBase"),
    s = t("ShopPageItem"),
    c = cc._decorator,
    p = c.ccclass,
    l =
        (c.property,
        c.menu,
        (function (t) {
            i(e, t);
            function e() {
                var e = (null !== t && t.apply(this, arguments)) || this;
                e.allPageItem = {};
                e.skip = !1;
                return e;
            }
            e.prototype.onShowEnd = function () {
                this.updateList();
                if (this.node.active) {
                    this.checkView();
                    this.resetCheckView();
                    EVUIEffView.on(EVUIEffView.udpateMovePageTime, this.resetCheckView.bind(this), this);
                    EVUIEffView.on(EVUIEffView.udpateShopPage, this.resetView.bind(this), this);
                }
            };
            e.prototype.resetView = function () {
                var t = this;
                if (this && this._pageView && this._pageView.$PageView) {
                    this._pageView.$PageView.removeAllPages();
                    this.allPageItem = {};
                    this.unschedule(this.addMove);
                    this.scheduleOnce(function () {
                        t.resetCheckView();
                        t.checkView();
                    });
                }
            };
            e.prototype.moveEvent = function () {
                this.resetCheckView();
            };
            e.prototype.onCloseStart = function () {
                EVUIEffView.offTarget(this);
                this.unschedule(this.addMove);
            };
            e.prototype.resetCheckView = function () {
                this.unschedule(this.addMove);
                this.scheduleOnce(this.addMove, 3);
            };
            e.prototype.addMove = function () {
                if (this && this._pageView && this._pageView.$PageView)
                    if (this.skip) this.skip = !1;
                    else {
                        var t = this._pageView.$PageView.getPages();
                        if (t.length > 0) {
                            var e = this._pageView.$PageView.getCurrentPageIndex();
                            e++;
                            e %= t.length;
                            this._pageView.$PageView.scrollToPage(e, 1);
                        }
                    }
            };
            e.prototype.checkView = function () {
                var t = this;
                if (this.checkList.length >= 2) {
                    for (var e = GameDataValue.getLastLv(), o = 0, a = 0; a < this.checkList.length; a++)
                        e >= this.checkList[a].level && (o = this.checkList[a].level);
                    var i = [],
                        n = [];
                    for (a = 0; a < this.checkList.length; a++)
                        if (o == this.checkList[a].level) {
                            i.push(this.checkList[a]);
                            n.push(this.allKeyList[a]);
                        }
                    var r = [
                            QLooperNode.tag_shopPage1,
                            QLooperNode.tag_shopPage2,
                            QLooperNode.tag_shopPage3,
                            QLooperNode.tag_shopPage4,
                            QLooperNode.tag_shopPage5
                        ],
                        s = !1;
                    for (a = 0; a < i.length && a < r.length; a++) {
                        var c = a;
                        GameDataValue.isOpenShopItem(0, c) || (s = !0);
                    }
                    if (!s) {
                        this.node.active = !1;
                        return;
                    }
                    var p = function (e) {
                            var o = e;
                            l.scheduleOnce(function () {
                                GameDataValue.isOpenShopItem(0, o) || t.addPage(r[o], i[o], o, n[o]);
                            }, 0.1 * o);
                        },
                        l = this;
                    for (a = 0; a < i.length && a < r.length; a++) p(a);
                    this._tip.$Label.string = this.tipNodeId;
                }
            };
            e.prototype.addPage = function (t, e, o, a) {
                var i = this;
                if (this && this._pageView && this._pageView.$PageView) {
                    var n = null;
                    if (!this.allPageItem[o]) {
                        if (!(n = QLooperNode.getNode(t))) {
                            this.scheduleOnce(function () {
                                i.addPage(t, e, o, a);
                            }, 0.2);
                            return;
                        }
                        this.allPageItem[o] = n;
                        this._pageView.$PageView.addPage(n);
                    }
                    (n = this.allPageItem[o]).active = !0;
                    var r = n.getComponent(s.default);
                    r && r.uplevelItem(e, o, a);
                }
            };
            return n([p], e);
        })(r.default));
o.default = l;
